<template>
  <tbc-dialog ref="dialog" title="京东商品采集" @confirm="startCrawl">
    <tbc-dynamic-form :form="dynamicForm" classes="compact">
      <!--      <template slot="url" slot-scope="scope">-->
      <!--        <el-input v-model="scope.item.value">-->
      <!--          <el-button icon="el-icon-s-promotion" slot="append" @click="startCrawl">开始采集</el-button>-->
      <!--        </el-input>-->
      <!--      </template>-->
    </tbc-dynamic-form>
  </tbc-dialog>
</template>
<script>

export default {

  name: 'goods-crawl',

  data() {
    return {
      dynamicForm: [
        {label: '链接地址', type: 'input', field: 'url', value: ''},
      ]
    }
  },

  methods: {

    show() {
      this.$refs.dialog.show()
      // this.dynamicForm.forEach(item => {
      //   if (typeof data[item.field] !== 'undefined') {
      //     item.value = data[item.field]
      //   }
      // })
    },

    close() {
      this.$refs.dialog.close()
    },

    async startCrawl() {
      let form = {}
      this.dynamicForm.forEach(item => form[item.field] = item.value)
      if (!form.url) return this.$message.error('请输入地址');
      const res = await this.http.post('/goods.gather/start', form)
      if (res.data.code !== 0) return this.$message.error(res.data.message);
      this.$message.success(res.data.message);
      let data = res.data.data
      this.gatherForm.forEach(item => {
        if (typeof data[item.field] !== 'undefined') {
          item.value = data[item.field]
        }
      })
    },

    async formSubmit() {
      let form = {}
      this.dynamicForm.forEach(item => form[item.field] = item.value)
      const res = await this.http.post('/goods/quickEdit', form)
      if (res.data.code !== 0) return this.$message.error(res.data.message);
      this.$message.success(res.data.message);
      this.$emit('success')
      this.close()
    }
  }
}
</script>